const { getExtraResourcesDir, getLogDir } = require('ee-core/ps');
const path = require("path");
const { cross } = require('ee-core/cross');
const { logger } = require('ee-core/log');

// class PythonService {
//     /**
//      * create python service
//      * In the default configuration, services can be started with applications. 
//      * Developers can turn off the configuration and create it manually.
//      */
//     async createPythonServer() {
//         const serviceName = "python";
//         const opt = {
//             name: 'pyapp',
//             cmd: path.join(getExtraResourcesDir(), 'py', 'pyapp'),
//             directory: path.join(getExtraResourcesDir(), 'py'),
//             args: ['--port=8000'],
//             windowsExtname: true,
//             appExit: true,
//         };
//         const entity = await cross.run(serviceName, opt);
//         logger.info('server name:', entity.name);
//         logger.info('server config:', entity.config);
//         logger.info('server url:', entity.getUrl());
//     }
// }

// // 导出类以便外部使用
// module.exports = PythonService;

class GoService {
    /**
     * create go service
     * In the default configuration, services can be started with applications. 
     * Developers can turn off the configuration and create it manually.
     */
    async createGoServer() {
        // method 1: Use the default Settings
        //const entity = await cross.run(serviceName);

        // method 2: Use custom configuration
        const serviceName = "go";
        const opt = {
            // 程序名称，一般填写可执行程序名
            name: 'goapp',
            cmd: path.join(getExtraResourcesDir(), 'goapp'),
            directory: getExtraResourcesDir(),
            // args: ['--port=8000'],
            args: [],
            // 程序退出时，是否退出electron应用
            appExit: true,
        }
        const entity = await cross.run(serviceName, opt);
        logger.info('server name:', entity.name);

        return;
    }
}

module.exports = GoService;
